﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using WPFDemoMVVM.Resources;
using WPFLocalizeExtension.Engine;

namespace WPFDemoMVVM.ViewModel
{
    public partial class LanguageChangeViewModel: ObservableObject
    {

        [RelayCommand]
        private void ChangeLanguage(string languageCode)
        {
            //if (string.IsNullOrWhiteSpace(languageCode))
            //    return;
            //// 切换语言资源
            //var dict = new ResourceDictionary();
            //switch (languageCode)
            //{
            //    case "en":
            //        dict.Source = new Uri("Language/en_Dictionary.xaml", UriKind.Relative);
            //        break;
            //    case "zh-CN":
            //        dict.Source = new Uri("Language/zh_Dictionary.xaml", UriKind.Relative);
            //        break;
            //    default:
            //        return;
            //}
            //// 替换 Application 的 Resource
            //Application.Current.Resources.MergedDictionaries.Clear();
            //Application.Current.Resources.MergedDictionaries.Add(dict);

            ////第二种方式切换语言资源
            //var culture = new CultureInfo(languageCode);
            //Thread.CurrentThread.CurrentCulture = culture;
            //Thread.CurrentThread.CurrentUICulture = culture;

            //////第三种方式切换语言资源
            var culture = new CultureInfo(languageCode);
            Thread.CurrentThread.CurrentCulture = culture;
            Thread.CurrentThread.CurrentUICulture = culture;
            LocalizeDictionary.Instance.Culture = culture;

            ////第四种方式换语言资源
            //var culture = new CultureInfo(languageCode);
            //Thread.CurrentThread.CurrentCulture = culture;
            //Thread.CurrentThread.CurrentUICulture = culture;
            //I18NExtension.Culture = culture;

        }


        [RelayCommand]
        private void ShowMessage()
        {
            //MessageBox.Show(Application.Current.TryFindResource("Hello").ToString(), Application.Current.TryFindResource("Prompt").ToString(), MessageBoxButton.OK, MessageBoxImage.Information);

            MessageBox.Show(Lang.Hello,Lang.Prompt, MessageBoxButton.OK, MessageBoxImage.Information);
        }


        //public  MetroWindow _mainWindow;

       

        //[RelayCommand]
        //private void OpenChild()
        //{
        //    var childWindow = new View.ChildWindow
        //    {
        //        Owner = _mainWindow
        //    };
        //    childWindow.ShowDialog(); // 或 Show() 非模态
        //}

    }
}
